home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / findtask.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-12  |  2.2 KB  |  104 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: findtask.c,v 1.4 1996/08/13 13:56:02 digulla Exp $
  4.     $Log: findtask.c,v $
  5.     Revision 1.4  1996/08/13 13:56:02  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:11  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang:
  15. */
  16. #include <exec/execbase.h>
  17. #include <aros/libcall.h>
  18.  
  19. /*****************************************************************************
  20.  
  21.     NAME */
  22.     #include <clib/exec_protos.h>
  23.  
  24. __AROS_LH1(struct Task *, FindTask,
  25.  
  26. /*  SYNOPSIS */
  27.     __AROS_LHA(STRPTR, name, A1),
  28.  
  29. /*  LOCATION */
  30.     struct ExecBase *, SysBase, 49, Exec)
  31.  
  32. /*  FUNCTION
  33.     Find a task with a given name or get the address of the current task.
  34.     Finding the address of the current task is a very quick function
  35.     call, but finding a special task is a very CPU intensive instruction.
  36.     Note that generally a task may already be gone when this function
  37.     returns.
  38.  
  39.     INPUTS
  40.     name - Pointer to name or NULL for current task.
  41.  
  42.     RESULT
  43.     Address of task structure found.
  44.  
  45.     NOTES
  46.  
  47.     EXAMPLE
  48.  
  49.     BUGS
  50.  
  51.     SEE ALSO
  52.  
  53.     INTERNALS
  54.  
  55.     HISTORY
  56.  
  57. ******************************************************************************/
  58. {
  59.     __AROS_FUNC_INIT
  60.  
  61.     struct Task *ret;
  62.  
  63.     /* Quick return for a quick argument */
  64.     if(name==NULL)
  65.     return SysBase->ThisTask;
  66.  
  67.     /* Always protect task lists with a Disable(). */
  68.     Disable();
  69.  
  70.     /* First look into the ready list. */
  71.     ret=(struct Task *)FindName(&SysBase->TaskReady,name);
  72.     if(ret==NULL)
  73.     {
  74.     /* Then into the waiting list. */
  75.     ret=(struct Task *)FindName(&SysBase->TaskWait,name);
  76.     if(ret==NULL)
  77.     {
  78.         /*
  79.         Finally test the current task. Note that generally
  80.         you know the name of your own task - so it is close
  81.         to nonsense to look for it this way.
  82.         */
  83.         char *s1=SysBase->ThisTask->tc_Node.ln_Name;
  84.         char *s2=name;
  85.  
  86.         /* Check as long as the names are identical. */
  87.         while(*s1++==*s2)
  88.         /* Terminator found? */
  89.         if(!*s2++)
  90.         {
  91.             /* Got it. */
  92.             ret=SysBase->ThisTask;
  93.             break;
  94.         }
  95.     }
  96.     }
  97.  
  98.     /* Return whatever I found. */
  99.     Enable();
  100.     return ret;
  101.     __AROS_FUNC_EXIT
  102. } /* FindTask */
  103.  
  104.